
<!doctype html>
<html lang="zh" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      
        <link rel="prev" href="../../AT_Framwork_Guide/How_To_Use_Esp8266_Tencent_Firmware_Connect_Iot_Explorer/">
      
      
        <link rel="next" href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/">
      
      <link rel="icon" href="../../../assets/favicon.png">
      <meta name="generator" content="mkdocs-1.4.3, mkdocs-material-9.1.19">
    
    
      
        <title>ElfLoader动态加载 - TobudOS Documentation</title>
      
    
    
      <link rel="stylesheet" href="../../../assets/stylesheets/main.eebd395e.min.css">
      
        
        <link rel="stylesheet" href="../../../assets/stylesheets/palette.ecc896b0.min.css">
      
      

    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
    <script>__md_scope=new URL("../../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#tobudos-elfloader" class="md-skip">
          跳转至
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="页眉">
    <a href="../../" title="TobudOS Documentation" class="md-header__button md-logo" aria-label="TobudOS Documentation" data-md-component="logo">
      
  <img src="../../../assets/logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            TobudOS Documentation
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              ElfLoader动态加载
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
          
            
            
            
            <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
            
              <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
            
            
            
            <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
            
              <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
        </form>
      
    
    
      <div class="md-header__option">
        <div class="md-select">
          
          <button class="md-header__button md-icon" aria-label="选择当前语言">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m12.87 15.07-2.54-2.51.03-.03A17.52 17.52 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04M18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12m-2.62 7 1.62-4.33L19.12 17h-3.24Z"/></svg>
          </button>
          <div class="md-select__inner">
            <ul class="md-select__list">
              
                <li class="md-select__item">
                  <a href="../../../ElfLoader_Guide/ElfLoader_Quick_Start/" hreflang="zh" class="md-select__link">
                    中文
                  </a>
                </li>
              
                <li class="md-select__item">
                  <a href="../../../en/ElfLoader_Guide/ElfLoader_Quick_Start/" hreflang="en" class="md-select__link">
                    English
                  </a>
                </li>
              
            </ul>
          </div>
        </div>
      </div>
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="查找">
        
          <a href="javascript:void(0)" class="md-search__icon md-icon" title="分享" aria-label="分享" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7 0-.24-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91 1.61 0 2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08Z"/></svg>
          </a>
        
        <button type="reset" class="md-search__icon md-icon" title="清空当前内容" aria-label="清空当前内容" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
        </button>
      </nav>
      
        <div class="md-search__suggest" data-md-component="search-suggest"></div>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            正在初始化搜索引擎
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://atomgit.com/tobudos/Document" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  </div>
  <div class="md-source__repository">
    Atomgit
  </div>
</a>
      </div>
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
            
<nav class="md-tabs" aria-label="标签" data-md-component="tabs">
  <div class="md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  <li class="md-tabs__item">
    <a href="../../" class="md-tabs__link">
      首页
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../Introduction/TobudOS_Brief_Introduction/" class="md-tabs__link">
      项目特性简介
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_KEIL/" class="md-tabs__link">
        内核移植指南
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../DevelopGuide/Development_Manual/" class="md-tabs__link">
        内核开发指南
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/" class="md-tabs__link">
        AT模组框架
      </a>
    </li>
  

      
        
  
  
    
  


  <li class="md-tabs__item">
    <a href="./" class="md-tabs__link md-tabs__link--active">
      ElfLoader动态加载
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/" class="md-tabs__link">
        固件升级
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../MicroPython_Guide/BearPi_MicroPython_QuickStart/" class="md-tabs__link">
      MicroPython开发指南
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../VFS_Guide/vfs/" class="md-tabs__link">
      文件系统
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../GUI_Guide/gui/" class="md-tabs__link">
      GUI开发
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../DevelopKit/1.EVB_MX_Plus_Quick_Start/" class="md-tabs__link">
        官方开发套件
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="导航栏" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../../" title="TobudOS Documentation" class="md-nav__button md-logo" aria-label="TobudOS Documentation" data-md-component="logo">
      
  <img src="../../../assets/logo.png" alt="logo">

    </a>
    TobudOS Documentation
  </label>
  
    <div class="md-nav__source">
      <a href="https://atomgit.com/tobudos/Document" title="前往仓库" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
  </div>
  <div class="md-source__repository">
    Atomgit
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../" class="md-nav__link">
        首页
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../Introduction/TobudOS_Brief_Introduction/" class="md-nav__link">
        项目特性简介
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
      
      
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
          内核移植指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3">
          <span class="md-nav__icon md-icon"></span>
          内核移植指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_KEIL/" class="md-nav__link">
        基于Keil移植TobudOS内核
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_IAR/" class="md-nav__link">
        基于IAR 移植TobudOS内核
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../Kernel_Porting/Porting_Manual_for_GCC/" class="md-nav__link">
        基于GCC 移植TobudOS内核
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
      
      
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
          内核开发指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4">
          <span class="md-nav__icon md-icon"></span>
          内核开发指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopGuide/Development_Manual/" class="md-nav__link">
        TobudOS内核开发指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopGuide/API_Reference/" class="md-nav__link">
        TobudOS内核API参考手册
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopGuide/CMSIS_RTOS_API_Use_Guide/" class="md-nav__link">
        TobudOS内核CMSIS适配API指南
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
      
      
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
          AT模组框架
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_5">
          <span class="md-nav__icon md-icon"></span>
          AT模组框架
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../AT_Framwork_Guide/AT_Firmware_and_SAL_Firmware_User_Guide/" class="md-nav__link">
        无线通信模组AT框架开发指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../AT_Framwork_Guide/How_To_Use_Esp8266_Tencent_Firmware_Connect_Iot_Explorer/" class="md-nav__link">
        基于AT框架和定制模组如何对接腾讯云IoT Explorer平台
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
        
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          ElfLoader动态加载
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="./" class="md-nav__link md-nav__link--active">
        ElfLoader动态加载
      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      目录
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#1-elfloader" class="md-nav__link">
    1. 什么是 elfLoader
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#2-elfloader" class="md-nav__link">
    2. elfLoader 组件的基本使用范式
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#3-elfloader-object" class="md-nav__link">
    3. elfLoader 组件的具体使用实例（object）
  </a>
  
    <nav class="md-nav" aria-label="3. elfLoader 组件的具体使用实例（object）">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#31" class="md-nav__link">
    3.1 编写一个模块的源码
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#32-object" class="md-nav__link">
    3.2 将模块编译成 object 文件
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#33" class="md-nav__link">
    3.3 将模块拷贝至文件系统
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#34" class="md-nav__link">
    3.4 运行示例工程
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#35" class="md-nav__link">
    3.5 注意
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#4-elfloader-shared-object" class="md-nav__link">
    4. elfLoader 组件的具体使用实例（shared-object）
  </a>
  
    <nav class="md-nav" aria-label="4. elfLoader 组件的具体使用实例（shared-object）">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#41" class="md-nav__link">
    4.1 编写一个模块的源码
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#42-shared-object" class="md-nav__link">
    4.2 将模块编译成 shared-object 文件
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#43" class="md-nav__link">
    4.3 将模块拷贝至文件系统
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#44" class="md-nav__link">
    4.4 运行示例代码
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#5-elfloader" class="md-nav__link">
    5. elfLoader 组件的文件访问扩展
  </a>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
      
      
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
          固件升级
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_7">
          <span class="md-nav__icon md-icon"></span>
          固件升级
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../OTA_Guide/OTA_Quick_Start_based_EVB_MX_Plus/" class="md-nav__link">
        基于EVB_MX的固件升级指南
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../OTA_Guide/In_Application_Programming_based_EVB_MX_Plus/" class="md-nav__link">
        基于EVB_MX的IAP开发指南
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../MicroPython_Guide/BearPi_MicroPython_QuickStart/" class="md-nav__link">
        MicroPython开发指南
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../VFS_Guide/vfs/" class="md-nav__link">
        文件系统
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../GUI_Guide/gui/" class="md-nav__link">
        GUI开发
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_11" >
      
      
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
      
      
        <label class="md-nav__link" for="__nav_11" id="__nav_11_label" tabindex="0">
          官方开发套件
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_11_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_11">
          <span class="md-nav__icon md-icon"></span>
          官方开发套件
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/1.EVB_MX_Plus_Quick_Start/" class="md-nav__link">
        EVB_MX+（STM32L4）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/2.EVB_LX_RISC-V_Quick_Start/" class="md-nav__link">
        EVB_LX（GD32V RISC-V）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/3.EVB_WL_Quick_Start/" class="md-nav__link">
        EVB_WL（STM32WL）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/4.EVB_G0_QuickStart/" class="md-nav__link">
        EVB_G0（STM32G0）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/5.EVB_AIoT_NXP_QuickStart/" class="md-nav__link">
        EVB_AIoT_NXP（RT1062）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/6.EVB_CH32V_QuickStart/" class="md-nav__link">
        EVB_CH32V（CH32V307）快速上手
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../DevelopKit/7.EVB_AIoT_STM32_QuickStart/" class="md-nav__link">
        EVB_AIoT_STM32（STM32H7）快速上手
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="目录">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      目录
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#1-elfloader" class="md-nav__link">
    1. 什么是 elfLoader
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#2-elfloader" class="md-nav__link">
    2. elfLoader 组件的基本使用范式
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#3-elfloader-object" class="md-nav__link">
    3. elfLoader 组件的具体使用实例（object）
  </a>
  
    <nav class="md-nav" aria-label="3. elfLoader 组件的具体使用实例（object）">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#31" class="md-nav__link">
    3.1 编写一个模块的源码
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#32-object" class="md-nav__link">
    3.2 将模块编译成 object 文件
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#33" class="md-nav__link">
    3.3 将模块拷贝至文件系统
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#34" class="md-nav__link">
    3.4 运行示例工程
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#35" class="md-nav__link">
    3.5 注意
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#4-elfloader-shared-object" class="md-nav__link">
    4. elfLoader 组件的具体使用实例（shared-object）
  </a>
  
    <nav class="md-nav" aria-label="4. elfLoader 组件的具体使用实例（shared-object）">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#41" class="md-nav__link">
    4.1 编写一个模块的源码
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#42-shared-object" class="md-nav__link">
    4.2 将模块编译成 shared-object 文件
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#43" class="md-nav__link">
    4.3 将模块拷贝至文件系统
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#44" class="md-nav__link">
    4.4 运行示例代码
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#5-elfloader" class="md-nav__link">
    5. elfLoader 组件的文件访问扩展
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  

  
    <a href="https://atomgit.com/tobudos/Document/edit/master/docs/ElfLoader_Guide/ElfLoader_Quick_Start.md" title="编辑此页" class="md-content__button md-icon">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
    </a>
  
  
    
      
    
    <a href="https://atomgit.com/tobudos/Document/raw/master/docs/ElfLoader_Guide/ElfLoader_Quick_Start.md" title="查看本页的源代码" class="md-content__button md-icon">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0 8a5 5 0 0 1-5-5 5 5 0 0 1 5-5 5 5 0 0 1 5 5 5 5 0 0 1-5 5m0-12.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5Z"/></svg>
    </a>
  


<h1 id="tobudos-elfloader">TobudOS elfLoader 组件</h1>
<h2 id="1-elfloader">1. 什么是 elfLoader</h2>
<p>elfLoader 是 TobudOS 提供的对 elf 格式文件进行加载并执行的组件，TobudOS 目前的 elfLoader 组件，提供目标文件（object）及共享目标文件（shared object）的动态加载支持。</p>
<h2 id="2-elfloader">2. elfLoader 组件的基本使用范式</h2>
<p>对于 elfLoader 来说，使用的基本范式流程为：</p>
<ul>
<li>将源代码编译成 object 或 shared-object 文件。</li>
<li>将 object 或 shared-object 文件拷贝到开发板可以访问的文件系统中。</li>
<li>调用 elfLoader 组件提供的 tos_elfloader_load 接口加载文件系统中的 object 或 shared-object 文件。</li>
<li>调用 elfLoader 组件提供的 tos_elfloader_find_symbol 查找已加载的模块中某个符号的加载地址（一般来说是一个函数），执行之。</li>
<li>如果后续业务不再需要这个模块，执行 tos_elfloader_unload 将模块卸载。</li>
</ul>
<h2 id="3-elfloader-object">3. elfLoader 组件的具体使用实例（object）</h2>
<h3 id="31">3.1 编写一个模块的源码</h3>
<div class="highlight"><pre><span></span><code> extern int d_e_a;

 int d_g_a = 3;

 static int d_s_a = 5;

 extern int f_e_a(int);

 static int f_s_a(void) {
     d_s_a += 7; // d_s_a = 12
 }

 int f_g_a(void) {
     f_s_a();

     d_g_a += d_s_a; // d_g_a = 15

     d_e_a += d_g_a; // + 15

     f_e_a(d_e_a);
 }
</code></pre></div>
<p>源码 1.c 如上，改模块中：</p>
<ul>
<li>引用了一个外部的符号 d_e_a（变量，这是一个应该在模块外定义的符号）</li>
<li>定义了一个全局符号 d_g_a（变量）</li>
<li>定义了一个模块内的静态符号 d_s_a（变量）</li>
<li>引用了一个外部的符号 f_e_a（函数，这是一个应该在模块外定义的符号）</li>
<li>定义了一个模块内的静态符号 f_s_a（函数）</li>
<li>定义了一个全局符号 f_g_a（函数）</li>
</ul>
<h3 id="32-object">3.2 将模块编译成 object 文件</h3>
<div class="highlight"><pre><span></span><code>arm-linux-gnueabihf-gcc -fno-builtin -nostdlib -mthumb -mthumb-interwork -mcpu=cortex-m4 -c 1.c -o 1.o
</code></pre></div>
<p>我这里假设读者已经在本地安装好 arm 交叉编译器，且本实例是基于 TobudOS 官方开发板（mcu 是 arm cortex-m4 核心），按照以上编译选项将 1.c 编译为 1.o</p>
<h3 id="33">3.3 将模块拷贝至文件系统</h3>
<p>将模块（1.o）拷贝至已进行 FAT32 格式化后的 sd 卡，将 sd 卡插入 TobudOS 官方开发板上的 sd 卡槽。</p>
<h3 id="34">3.4 运行示例工程</h3>
<div class="highlight"><pre><span></span><code>TobudOS\board\TobudOS_EVB_MX_Plus\KEIL\elfloader_relocatable_object
</code></pre></div>
<p>用 keil 打开以上路径中的示例工程：</p>
<ul>
<li>添加 d_e_a 及 f_e_a 实现</li>
</ul>
<p>因为 1.o 依赖此两个外部符号，因而需要在内核中定义这两个符号</p>
<div class="highlight"><pre><span></span><code>int d_e_a = 9;

int f_e_a(int a)
{
    /* a = d_e_a + d_g_a = d_e_a + 15 = 24 */
    printf(&quot;f_e_a:  %d\n&quot;, a);
    return 0;
}
</code></pre></div>
<ul>
<li>添加系统符号表</li>
</ul>
<div class="highlight"><pre><span></span><code>const el_symbol_t el_symbols[] = {
    { &quot;d_e_a&quot;, &amp;d_e_a },
    { &quot;f_e_a&quot;, f_e_a },
    { K_NULL, K_NULL },
};
</code></pre></div>
<p>按照以上格式，定义 el_symbols 符号表，符号表中包含 1.o 中依赖的两个外部符号地址。</p>
<ul>
<li>编写 elfLoader 使用案例代码</li>
</ul>
<div class="highlight"><pre><span></span><code>void application_entry(void *arg)
{
    int fd;
    el_module_t module;

    extern vfs_blkdev_ops_t sd_dev;
    extern vfs_fs_ops_t fatfs_ops;

    if (tos_vfs_block_device_register(&quot;/dev/sd&quot;, &amp;sd_dev) != VFS_ERR_NONE) {
        return;
    }

    if (tos_vfs_fs_register(&quot;fatfs_sd&quot;, &amp;fatfs_ops) != VFS_ERR_NONE) {
        return;
    }

    if (tos_vfs_fs_mount(&quot;/dev/sd&quot;, &quot;/fs/fatfs_sd&quot;, &quot;fatfs_sd&quot;) != VFS_ERR_NONE) {
        printf(&quot;mount failed!\n&quot;);
        return;
    }

    fd = tos_vfs_open(&quot;/fs/fatfs_sd/1.o&quot;, VFS_OFLAG_READ | VFS_OFLAG_EXISTING);
    if (fd &lt; 0) {
        return;
    }

    if (tos_elfloader_load(&amp;module, fd) != ELFLOADER_ERR_NONE) {
        return;
    }

    void *addr = tos_elfloader_find_symbol(&amp;module, &quot;f_g_a&quot;);
    if (!addr) {
        printf(&quot;symbol NOT FOUND: %s\n&quot;, &quot;f_g_a&quot;);
        return;
    }

    printf(&quot;addr: %x\n&quot;, addr);

    typedef int (*fp_t)(void);
    /* call f_g_a in 1.o */
    ((fp_t)addr)();

    tos_elfloader_unload(&amp;module);

    tos_vfs_close(fd);
}
</code></pre></div>
<p>以上代码：使用 TobudOS 的 vfs 组件挂载 sd 卡上的 FAT32 文件系统，并打开文件系统上的 1.o 获取文件描述符 fd，将 fd 作为 tos_elfloader_load 的入参，加载这个模块并获取模块的句柄 module，使用 tos_elfloader_find_symbol 接口在 module 中查找 f_g_a 符号（函数）的加载地址，并执行之。</p>
<p>根据 1.c 中 f_g_a 的逻辑，最终会调用 f_e_a 将 d_e_a 最终的值打印出来，根据运算逻辑，d_e_a 的最终值应该为 24。</p>
<ul>
<li>调用 tos_elfloader_unload 卸载该模块，调用 tos_vfs_close 接口关闭文件描述符 fd。</li>
</ul>
<h3 id="35">3.5 注意</h3>
<p>对于一般的 mcu 来说，可执行代码位于 FLASH 上，而模块的可执行代码及数据皆被加载至 RAM 上。而一般来说 FLASH 和 RAM 之间的地址相隔甚远，这会导致加载 object 文件的重定位阶段，某些重定位类型无法顺利完成重定位操作，进而导致 object 文件加载失败。</p>
<h2 id="4-elfloader-shared-object">4. elfLoader 组件的具体使用实例（shared-object）</h2>
<p>共享目标文件 (shared-object) 的装载及运行与 object 文件类似</p>
<h3 id="41">4.1 编写一个模块的源码</h3>
<p>参考 3.1 节</p>
<h3 id="42-shared-object">4.2 将模块编译成 shared-object 文件</h3>
<div class="highlight"><pre><span></span><code>arm-linux-gnueabihf-gcc -fno-builtin -nostdlib -mthumb -mthumb-interwork -fPIC -mcpu=cortex-m4 -c 1.c -o 1.o

arm-linux-gnueabihf-ld -fno-builtin -nostdlib -fPIC -shared -z max-page-size=0x4 1.o -o 1.so
</code></pre></div>
<p>我这里假设读者已经在本地安装好 arm 交叉编译器，且本实例是基于 TobudOS 官方开发板（mcu 是 arm cortex-m4 核心），按照以上编译选项将 1.c 编译为 1.so</p>
<h3 id="43">4.3 将模块拷贝至文件系统</h3>
<p>参考 3.3 节</p>
<h3 id="44">4.4 运行示例代码</h3>
<div class="highlight"><pre><span></span><code>TobudOS\board\TobudOS_EVB_MX_Plus\KEIL\elfloader_shared_object
</code></pre></div>
<p>用 keil 打开以上路径中的示例工程，工程中的具体代码与 object 工程类似，参考 3.4 节，不再赘述。</p>
<h2 id="5-elfloader">5. elfLoader 组件的文件访问扩展</h2>
<p>elfLoader 的组件实现，对于模块文件的访问，是通过 elfloader_fd_read 接口来进行的：</p>
<div class="highlight"><pre><span></span><code>__KNL__ __WEAK__ el_err_t elfloader_fd_read(int fd, uint32_t offset, void *buf, size_t len)
{
    if (tos_vfs_lseek(fd, (vfs_off_t)offset, VFS_SEEK_SET) &lt; 0) {
        return ELFLOADER_ERR_FD_READ_FAILED;
    }

    if (tos_vfs_read(fd, buf, len) &lt; 0) {
        return ELFLOADER_ERR_FD_READ_FAILED;
    }

    return ELFLOADER_ERR_NONE;
}
</code></pre></div>
<p>此接口接收四个参数：</p>
<ul>
<li>fd</li>
</ul>
<p>文件的描述符 fd。此 fd 可以不用拘泥于文件系统的 fd，fd 只是一个文件的抽象。</p>
<ul>
<li>offset</li>
</ul>
<p>对文件的 offset 偏移处进行读取。</p>
<ul>
<li>buf</li>
</ul>
<p>文件读取的数据缓冲</p>
<ul>
<li>len</li>
</ul>
<p>文件读取的长度</p>
<p>elfloader_fd_read 的实现位于 tos_elfloader_fd_read-vfs.c 中，默认实现是基于 TobudOS 的 vfs 接口进行文件访问。</p>
<p>现在假设有这样的场景：用户在使用 elfLoader 时，不希望通过 vfs 框架来进行文件访问（用户的场景可能根本就没有文件系统，或者压根不希望通过文件系统来访问模块），比如用户将编译好的模块烧写进裸 FLASH 的固定偏移处，假设有这种场景：</p>
<div class="highlight"><pre><span></span><code>uint32_t offset_of_modules[] = {
    0x8000 0000,
    0x8000 2000,
    0x8000 4000,
};
</code></pre></div>
<p>用户分别在 FLASH 的 0x8000 0000、0x8000 2000、0x8000 4000 偏移处烧写了三个 shared-object 文件，用户如何不通过文件系统框架来实现模块的加载运行呢？</p>
<p>业务代码中，希望通过 fd 为 0 时，加载 0x8000 0000 处的模块，通过 fd 为 1 时，加载 0x8000 2000 处的模块，通过 fd 为 2 时，加载 0x8000 4000 处的模块。代码如下：</p>
<div class="highlight"><pre><span></span><code>void application_entry(void *arg)
{
    el_module_t module0, module1, module2;

    if (tos_elfloader_load(&amp;module0, 0) != ELFLOADER_ERR_NONE) {
        return;
    }

    void *addr = tos_elfloader_find_symbol(&amp;module0, &quot;f_g_a&quot;);
    if (!addr) {
        printf(&quot;symbol NOT FOUND: %s\n&quot;, &quot;f_g_a&quot;);
        return;
    }

    if (tos_elfloader_load(&amp;module1, 1) != ELFLOADER_ERR_NONE) {
        return;
    }

    if (tos_elfloader_load(&amp;module2, 2) != ELFLOADER_ERR_NONE) {
        return;
    }

    tos_elfloader_unload(&amp;module0);
    tos_elfloader_unload(&amp;module1);
    tos_elfloader_unload(&amp;module2);
}
</code></pre></div>
<p>业务代码里，并不需要依赖文件系统，fd 本质上只是只是一种抽象，它可以与文件系统无关。</p>
<p>现在假设用户已经实现了 FLASH 的读驱动接口 flash_read，要做到上述诉求，只需要重新实现 elfloader_fd_read 即可：</p>
<div class="highlight"><pre><span></span><code>el_err_t elfloader_fd_read(int fd, uint32_t offset, void *buf, size_t len)
{
    uint32_t offset = offset_of_modules[fd];

    if (flash_read(offset, buf, len) &lt; 0) {
        return ELFLOADER_ERR_FD_READ_FAILED;
    }

    return ELFLOADER_ERR_NONE;
}
</code></pre></div>
<p>可以看出来，TobudOS 的组件实现，依赖一定程度的抽象，但此抽象又并不与某个特定框架强耦合。对于 elfLoader 组件来说，用户即可以基于文件系统实现对模块的访问，经过少量的适配工作，也完全可以基于裸 FLASH 驱动来进行模块的访问。</p>





                
              </article>
            </div>
          
          
        </div>
        
          <button type="button" class="md-top md-icon" data-md-component="top" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg>
            回到页面顶部
          </button>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
    <div class="md-copyright__highlight">
      Copyright &copy; 2023 TobudOS
    </div>
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    <script id="__config" type="application/json">{"base": "../../..", "features": ["content.action.edit", "content.action.view", "content.code.annotate", "content.tooltips", "navigation.indexes", "navigation.sections", "navigation.tabs", "navigation.top", "navigation.tracking", "search.highlight", "search.share", "search.suggest", "toc.follow"], "search": "../../../assets/javascripts/workers/search.74e28a9f.min.js", "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}}</script>
    
    
      <script src="../../../assets/javascripts/bundle.220ee61c.min.js"></script>
      
    
  </body>
</html>